#include "StdAfx.h"

#include "MainWnd.h"

using boost::wformat;

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
	LPSTR lpCmdLine, int nShowCmd){

	
	ATOM atom = 0;
	MainWnd mainWnd;

	try {
		atom = MainWnd::Register(hInstance);
		HWND hMainWnd = TWS(CreateWindowEx(0L, MAINWND_CLASS_NAME,
			L"Mo",
			WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
			NULL, NULL, hInstance, reinterpret_cast<LPVOID>(&mainWnd)));
		mainWnd.SetHWnd(hMainWnd);

		assert(hMainWnd != NULL);

		PostMessage(hMainWnd, UM_CREATEDEVICE, NULL, NULL);

		ShowWindow(hMainWnd, SW_SHOW);
		UpdateWindow(hMainWnd);

		BOOL bRet;
		MSG msg;

		while( (bRet = GetMessage( &msg, NULL, 0, 0 )) != 0)
			if (bRet == -1){
				OutputDebugString(L"Error occurred calling GetMessage.\n");
				return -1;
			}
			else{
				TranslateMessage(&msg); 
				DispatchMessage(&msg); 
			}
	}
	catch(rt::hr_message&  bang){
		return rt::display_error(bang);
	}
	catch(...){
		return -1;
	}
	return 0;
}